package bearworker.zxl.utils;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSONObject;

import io.netty.util.internal.StringUtil;

/**
 * Created by 逍遥的熊 on 2017/11/28.
 */
public class CommUtil {

    public static Map<String,Object> toResMap(String code,String msg,Object data){
        Map<String,Object> map = new HashMap<>();
        map.put("code",code);
        map.put("msg",msg);
        map.put("data",data);

        return map;
    }
    
    public static <T> T jsonToBean(Map<String, String> params,String ClassName, Class<T> beanClass){
    	String bodyStr = params.get("bodyStr");
    	if(StringUtils.isNotBlank(bodyStr)) {
    		JSONObject jsonObject = JSONObject.parseObject(bodyStr);
        	String beanClassJson = jsonObject.getString(ClassName);
        	if(StringUtils.isNotBlank(beanClassJson)) {
        		return (T) JSONObject.parseObject(beanClassJson, beanClass);
        	}
    	}
		return null;
    	
    	
    }
}
